package com.dragon.client.controller.auth;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.auth.IModService;
import com.dragon.repository.domain.dto.ModDTO;
import com.dragon.repository.domain.vo.ModVO;
import com.dragon.repository.entity.Mod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 模块表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-20
 */
@RestController
@RequestMapping("mod")
@Api(tags = "控制台")
public class ModController {

    @Autowired
    IModService service;

    @GetMapping("modTree")
    @ApiOperation("控制台列表")
    public ResponseData<List<ModDTO>> modTree() {
        List<Mod> mods = service.modList();
        return ResponseData.success(ModDTO.convertList(mods));
    }

    @PostMapping("add")
    @ApiOperation("控制台模块添加")
    public ResponseData modAdd(@RequestBody @Validated(Insert.class)ModVO vo) {
        service.modAdd(ModVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation("控制台模块更新")
    public ResponseData modUpdate(@RequestBody @Validated(Update.class)ModVO vo) {
        service.modUpdate(ModVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("控制台模块删除")
    public ResponseData modDelete(Integer id) {
        service.modDelete(id);
        return ResponseData.success();
    }


}
